Post-industrialization era has been marked with increased GDP growth for countries, as well as an improved standard of living for the people. However, throughout the past years, people have not realized the importance of climate and the implications of climatic changes on our society. With increasing globalization, drastic visible climatic changes – and their impact on society— have been observed that has led to people realizing the gravity of the situation at hand. Globalization leads to countries increasing their production in order to meet the local demand as well as the international demand. Such increased global demands have led to countries using more fossil fuel to run the machinery, which has led to increased air pollution that in-turn has started affecting our ecosystem and health of the people.
Many of the sources of outdoor air pollution are also sources of high CO2 emissions. A major source of carbon dioxide is the burning of fossil fuel—mostly by the energy and transport sectors. In regions that are prone to temperature and precipitation pattern changes due to climate change, it is very much likely that the frequency and severity of forest fires will also increase, destroying the ecosystem and the habitants, while simultaneously releasing more air pollutants.[1] Household air pollution from cooking with solid fuels has accounted for 3.8 millions deaths in the year 2016.[2] Similar to household pollution, outdoor air pollution in both cities and rural areas was estimated to cause 4.2 million premature deaths worldwide in the year 2016.[3]
[1] “Ambient air pollution: Health impacts”, World Health Organization. https://www.who.int/airpollution/ambient/health-impacts/en/
[2] “Mortality from household air pollution”, World Health Organization, 2016. _https://www.who.int/gho/phe/indoor_air_pollution/burden/en/_
[3] “Ambient Air Quality and Health”, World Health Organization, 2018. https://www.who.int/en/news-room/fact-sheets/detail/ambient-(outdoor)-air-quality-and-health
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import plotly as plotly
import plotly.offline as py
import plotly.graph_objs as go
import plotly.express as px
#%matplotlib inline
Our World in Data is a public good [4] :
This is why all the work we ever do is made available in its entirety as a public good
Visualizations and text are licensed under CC BY and may be freely used for any purpose.
The data is available for download.
And all code we write is open-sourced under the MIT license and can be found on GitHub.
CO2emissions = pd.read_csv("annual-co2-emissions-per-country.csv")
FossilFuelConsumption = pd.read_csv("fossil-fuel-consumption-by-fuel-type.csv")
GreenGasEmissions = pd.read_csv("greenhouse-gas-emissions-by-gas.csv")
GDPpercapita = pd.read_csv("maddison-data-gdp-per-capita-in-2011us.csv")
RenewableEnergyConsumtion = pd.read_csv("modern-renewable-energy-consumption.csv")
CO2bySource = pd.read_csv("CO2-by-source.csv")
CO2emissions.head()
FossilFuelConsumption.head()
GreenGasEmissions.head()
GDPpercapita.head()
RenewableEnergyConsumtion.head()
CO2bySource.head()
CO2emissions.rename(columns={"Entity": "Country"}, inplace = True)
FossilFuelConsumption.rename(columns={"Entity": "Country"}, inplace = True)
GreenGasEmissions.rename(columns={"Entity": "Country"}, inplace = True)
GDPpercapita.rename(columns={"Entity": "Country"}, inplace = True)
GDPpercapita.rename(columns={"GDP per capita (int.-$) ($)": "GDP per capita (2011USD)"}, inplace = True)
RenewableEnergyConsumtion.rename(columns={"Entity": "Country"}, inplace = True)
CO2bySource.rename(columns={"Entity": "Country"}, inplace = True)
CO2emissions = CO2emissions[CO2emissions.Year >= 1985]
FossilFuelConsumption = FossilFuelConsumption[FossilFuelConsumption.Year >= 1985]
GreenGasEmissions = GreenGasEmissions[GreenGasEmissions.Year >= 1985]
GDPpercapita = GDPpercapita[GDPpercapita.Year >= 1985]
RenewableEnergyConsumtion = RenewableEnergyConsumtion[RenewableEnergyConsumtion.Year >= 1985]
CO2bySource = CO2bySource[CO2bySource.Year >= 1985]
CO2bySource.drop(columns = ['Cement (tonnes)', 'Flaring (tonnes)'], inplace = True)
G20 = {'Country': ['Argentina', 'Australia', 'Brazil', 'Canada', 'China', 'France', 'Germany', 'India', 'Indonesia', 'Italy', 'Japan', 'Mexico', 'Russia', 'Saudi Arabia', 'South Africa', 'South Korea', 'Turkey', 'United Kingdom', 'United States']}
G20Countries = pd.DataFrame(G20)
# G20Countries.columns.names = 'Country'
G20Countries.head()
CO2emissionsG20 = pd.merge(CO2emissions, G20Countries, on='Country', how='inner').sort_values(by='Country')
FossilFuelConsumptionG20 = pd.merge(FossilFuelConsumption, G20Countries, on='Country', how='inner').sort_values(by='Country')
GDPpercapitaG20 = pd.merge(GDPpercapita, G20Countries, on='Country', how='inner').sort_values(by='Country')
GreenGasEmissionsG20 = pd.merge(GreenGasEmissions, G20Countries, on='Country', how='inner').sort_values(by='Country')
RenewableEnergyConsumtionG20 = pd.merge(RenewableEnergyConsumtion, G20Countries, on='Country', how='inner').sort_values(by='Country')
CO2bySourceG20 = pd.merge(CO2bySource, G20Countries, on='Country', how='inner').sort_values(by='Country')
CO2emissionsG20.sort_values(['Country', 'Year'], inplace = True)
FossilFuelConsumptionG20.sort_values(['Country', 'Year'], inplace = True)
GDPpercapitaG20.sort_values(['Country', 'Year'], inplace = True)
GreenGasEmissionsG20.sort_values(['Country', 'Year'], inplace = True)
RenewableEnergyConsumtionG20.sort_values(['Country', 'Year'], inplace = True)
CO2bySourceG20.sort_values(['Country', 'Year'], inplace = True)
CO2emissionsG20.head()
FossilFuelConsumptionG20.head()
GDPpercapitaG20.head()
GreenGasEmissionsG20.head()
RenewableEnergyConsumtionG20.head()
CO2bySourceG20.head()
GreenGasEmissionsG20.replace(0, np.nan, inplace=True)
GreenGasEmissionsG20 = GreenGasEmissionsG20.groupby('Country').apply(lambda group: group.interpolate(method= 'linear', limit_direction = 'both'))
#CO2emissionsG20 and GreenGasEmissionsG20 are in Million tonnes from now onwards
CO2emissionsG20['Annual CO₂ emissions (tonnes)'] = CO2emissionsG20['Annual CO₂ emissions (tonnes)']/1000000 #Million tonnes
GreenGasEmissionsG20['SF₆ gases (tonnes)'] = GreenGasEmissionsG20['SF₆ gases (tonnes)']/1000000
GreenGasEmissionsG20['PFC gases (tonnes)'] = GreenGasEmissionsG20['PFC gases (tonnes)']/1000000
GreenGasEmissionsG20['HFC gases (tonnes)'] = GreenGasEmissionsG20['HFC gases (tonnes)']/1000000
GreenGasEmissionsG20['Nitrous oxide (N₂O) (tonnes)'] = GreenGasEmissionsG20['Nitrous oxide (N₂O) (tonnes)']/1000000
GreenGasEmissionsG20['Methane (CH₄) (tonnes)'] = GreenGasEmissionsG20['Methane (CH₄) (tonnes)']/1000000
GreenGasEmissionsG20['Carbon Dioxide (CO₂) (tonnes)'] = GreenGasEmissionsG20['Carbon Dioxide (CO₂) (tonnes)']/1000000
CO2emissionsG20.rename(columns={"Annual CO₂ emissions (tonnes)": "Annual CO₂ emissions (Million tonnes)"}, inplace = True)
GreenGasEmissionsG20.rename(columns={"SF₆ gases (tonnes)": "SF₆ gases (Million tonnes)"}, inplace = True)
GreenGasEmissionsG20.rename(columns={"PFC gases (tonnes)": "PFC gases (Million tonnes)"}, inplace = True)
GreenGasEmissionsG20.rename(columns={"HFC gases (tonnes)": "HFC gases (Million tonnes)"}, inplace = True)
GreenGasEmissionsG20.rename(columns={"Nitrous oxide (N₂O) (tonnes)": "Nitrous oxide (N₂O) (Million tonnes)"}, inplace = True)
GreenGasEmissionsG20.rename(columns={"Methane (CH₄) (tonnes)": "Methane (CH₄) (Million tonnes)"}, inplace = True)
GreenGasEmissionsG20.rename(columns={"Carbon Dioxide (CO₂) (tonnes)": "Carbon Dioxide (CO₂) (Million tonnes)"}, inplace = True)
CO2emissionsG20.head()
GreenGasEmissionsG20.index = [GreenGasEmissionsG20.Country, GreenGasEmissionsG20.Year]
GreenGasEmissionsG20_1 = GreenGasEmissionsG20.drop(columns = 'Code')
GreenGasEmissionsG20.drop(columns = ['Country', 'Code', 'Year'], inplace = True)
GreenGasEmissionsG20 = GreenGasEmissionsG20.stack().reset_index()
GreenGasEmissionsG20.rename(columns={"level_2": "Green House Gases"}, inplace = True)
GreenGasEmissionsG20.rename(columns={0: "GreenGasEmissions (Million tonnes)"}, inplace = True)
GreenGasEmissionsG20.head()
One of the main concerns faced globally is the amount of fossil fuels burnt and consequently the amount of air pollutants released into the atmosphere by burning these fossil fuels. Many types of health ailments and consequently deaths are linked to the extent of exposure to air pollutants. “Collectively, the G20 economies account for around 90% of the gross world product (GWP), 80% of world trade (or, if excluding EU intra-trade, 75%), two-thirds of the world population, and approximately half of the world land area.”[5] Thus, the global economy is majorly influenced by the G20 nations which are highly developed economies in the world and to meet their expanding need for energy, these countries are also the largest consumers of fossil fuels. Hence, we want to analyze how their economic growth influences the consumption of fossil fuels and air pollutants like CO and CO2 emissions. Another point of interest in this study is to measure how much of renewable resources the aforementioned counties are using for their energy needs and has this decreased the amount of air pollutants being released into the atmosphere. Below are some of the questions that we will be explaining by analyzing the data:
[5]“Information about G20 countries” https://en.wikipedia.org/wiki/G20
fig = px.line(CO2emissionsG20, x='Year', y='Annual CO₂ emissions (Million tonnes)',color='Country',
line_group='Country', hover_name='Country')
fig.update_layout(legend_orientation="h", legend=dict(x=-.1, y=1.3))
fig.show()
fig = px.line(CO2emissionsG20, x='Year', y='Annual CO₂ emissions (Million tonnes)', line_group='Country', color='Country',
hover_name='Country')
fig.update_layout(xaxis_type="log", yaxis_type="log", legend_orientation="h", legend=dict(x=-.1, y=1.3))
fig.show()
Line graph shows trend of (CO2) emissions by different countries over the period of 1985 to 2017. Annual (CO2) emissions is in Million Tonnes which is on y-axis with years on x-axis. We have plotted a normal line graph and another one with log axis transformation, which allows us to visualize the trend for non-dominant countries which would otherwise be not visible clearly. In this plot multiple trends are be observed, US starts as the top most country in (CO2) emissions in 1985 and continues to increse until 2007 and from then it sligthly decreases and stabilizes at around 5,500 million tonnes with second place in 2017 whereas Russia starts in second place in 1985 and continues to grow a little unitl 1990 and then it drops for the next decade until 2000, after that it stabilizes but again slowly climbs to 1692 million tonnes (4th place) in 2014. China on the other hand starts at 3rd place with 1951 million tonnes and climbs to top position with 9838 million tonnes in 2014, which is close to 4 times of its 1985 value and double the US value in 2017. India starts at 7th place with 424 million tonnes in 1985 and climbs to 3rd position with 2466 million tonnes, close to 6 times from 1985 value. This is because of the rapid industrialization of India and China.
fig = px.line(GreenGasEmissionsG20, x='Year', y='GreenGasEmissions (Million tonnes)', color='Green House Gases',
line_group='Country', hover_name='Country')
fig.update_layout(legend_orientation="h", legend=dict(x=-.1, y=1.1))
fig.show()
fig = px.line(GreenGasEmissionsG20, x='Year', y='GreenGasEmissions (Million tonnes)', color='Green House Gases',
line_group='Country', hover_name='Country')
fig.update_layout(xaxis_type="log", yaxis_type="log", legend_orientation="h", legend=dict(x=-.1, y=1.1))
fig.show()
Line graph shows trend of different greenhouse gas emissions by different countries over the period of 1985 to 2014.
#creating a new dataframe for the year 1985,2000 and 2015.This dataframe will only have values of the FossilFuelConsumptionG20
#when the column year is equal to 1985,2000 and 2015
FossilFuelConsumptionG20_2015=FossilFuelConsumptionG20[FossilFuelConsumptionG20.Year==2015]
FossilFuelConsumptionG20_2000=FossilFuelConsumptionG20[FossilFuelConsumptionG20.Year==2000]
FossilFuelConsumptionG20_1985=FossilFuelConsumptionG20[FossilFuelConsumptionG20.Year==1985]
#suprimposing imformation of the same dataframe(i.e different fossil fuel type consumptions)
#using the go.figure method from the plotly library
fig = go.Figure(go.Bar(x =FossilFuelConsumptionG20_1985.Country, y=FossilFuelConsumptionG20_1985['Oil (terawatt-hours)'], name='Oil (terawatt-hours)'))
fig.add_trace(go.Bar(x=FossilFuelConsumptionG20_1985.Country, y=FossilFuelConsumptionG20_1985['Gas (terawatt-hours)'], name='Gas (terawatt-hours)'))
fig.add_trace(go.Bar(x=FossilFuelConsumptionG20_1985.Country, y=FossilFuelConsumptionG20_1985['Coal (terawatt-hours)'], name='Coal (terawatt-hours)'))
#using the stack argument in the fig.layout mode which, stacks the information in one bar
fig.update_layout(barmode='stack', xaxis={'categoryorder':'category ascending'},title_text='G20 Fossil Fuels Usage in the year 1985',yaxis=dict(
title='Terawatt-hours'))
fig.show()
#same idea as before, except for dataframe 2000(i.e values that are only for the year 2000)
fig = go.Figure(go.Bar(x =FossilFuelConsumptionG20_2000.Country, y=FossilFuelConsumptionG20_2000['Oil (terawatt-hours)'], name='Oil (terawatt-hours)'))
fig.add_trace(go.Bar(x=FossilFuelConsumptionG20_2000.Country, y=FossilFuelConsumptionG20_2000['Gas (terawatt-hours)'], name='Gas (terawatt-hours)'))
fig.add_trace(go.Bar(x=FossilFuelConsumptionG20_2000.Country, y=FossilFuelConsumptionG20_2000['Coal (terawatt-hours)'], name='Coal (terawatt-hours)'))
fig.update_layout(barmode='stack', xaxis={'categoryorder':'category ascending'},title_text='G20 Fossil Fuels Usage in the year 2000',yaxis=dict(
title='Terawatt-hours'))
fig.show()
#same idea as before, except for dataframe 2015(i.e values that are only for the year 2015)
fig = go.Figure(go.Bar(x =FossilFuelConsumptionG20_2015.Country, y=FossilFuelConsumptionG20_2015['Oil (terawatt-hours)'], name='Oil (terawatt-hours)'))
fig.add_trace(go.Bar(x=FossilFuelConsumptionG20_2015.Country, y=FossilFuelConsumptionG20_2015['Gas (terawatt-hours)'], name='Gas (terawatt-hours)'))
fig.add_trace(go.Bar(x=FossilFuelConsumptionG20_2015.Country, y=FossilFuelConsumptionG20_2015['Coal (terawatt-hours)'], name='Coal (terawatt-hours)'))
fig.update_layout(barmode='stack', xaxis={'categoryorder':'category ascending'},title_text='G20 Fossil Fuels Usage in the year 2015',yaxis=dict(
title='Terawatt-hours'))
fig.show()
The bar graph shows trend of different fossil fuel consumption different countries in the years 1985, 2000, and 2015. US start as the top fossil fuel usage country in 1985 with 18,566 terawatt-hours total comprising of 8256, 5188, and 5122 terawatt-hours of Oil, Gas, and Coal respectively. China on the otherhand starts at third position with 5918 terawatt-hours total fossil fuel comprising of 1043, 139, and 4736 terawatt-hours of Oil, Gas, and Coal respectively. In 2015 China becomes top fossil fuel user with 30827 terawatt-hours total fossil fuels consumption comprising of 6534, 2038, and 22255 terawatt-hours of Oil, Gas, and Coal respectively whereas the US is in second spot with 22779 terawatt-hours total fossil fuels consumption comprising of 9960, 8263, and 4556 terawatt-hours of Oil, Gas, and Coal respectively. It is double whammy, that China not only became the top fossil fuel user but also the composition is alarming because the amount Coal is used.
CO2bySourceG20 and FossilFuelConsumptionG20 datasets will be used in this visualization. Since the units in the CO2bySourceG20 dataset is tonnes of CO2 emissions by sources like Oil, Coal and Gas whereas the units in dataset FossilFuelConsumptionG20 is (terawatt-hours). To overcome this issue we calculated percentages of the individual contribution to the total, like how much percentage of CO2 emissions is from burning Oil, Coal, and Gas by each country and year. Similarly how much percentage of Oil, Gas, and Coal is burned by individual country that year. For example, in 2014 47.88% of the total CO2 emissions by Argentina is by burning Oil, where total CO2 emissions is by burning Oil, Coal, and Gas in 2014. Similarly CO2 emissions by burning Gas was 49.16% and Coal was 2.96% in 2014 for Argentina. On Fossil fuel consumption similarly percentages are 41.62%, 56.40%, and 1.98% for Oil, Gas, and Coal for Argentina in 2014.
CO2bySourceG20.head()
FossilFuelConsumptionG20.head()
CO2bySourceG20_P = CO2bySourceG20.drop(columns = ['Code'])
CO2bySourceG20_P['Total'] = CO2bySourceG20_P['Oil (tonnes)'] + CO2bySourceG20_P['Coal (tonnes)'] + CO2bySourceG20_P['Gas (tonnes)']
CO2bySourceG20_P['Oil (tonnes)'] = CO2bySourceG20_P['Oil (tonnes)']/CO2bySourceG20_P['Total']*100
CO2bySourceG20_P['Coal (tonnes)'] = CO2bySourceG20_P['Coal (tonnes)']/CO2bySourceG20_P['Total']*100
CO2bySourceG20_P['Gas (tonnes)'] = CO2bySourceG20_P['Gas (tonnes)']/CO2bySourceG20_P['Total']*100
CO2bySourceG20_P.drop(columns = ['Total'], inplace=True)
CO2bySourceG20_P.index = [CO2bySourceG20_P.Country, CO2bySourceG20_P.Year]
CO2bySourceG20_P = CO2bySourceG20_P[['Oil (tonnes)', 'Gas (tonnes)', 'Coal (tonnes)']]
CO2bySourceG20_1992 = CO2bySourceG20_P.xs(1992, level=1, axis=0, drop_level=False)
CO2bySourceG20_2002 = CO2bySourceG20_P.xs(2002, level=1, axis=0, drop_level=False)
CO2bySourceG20_2014 = CO2bySourceG20_P.xs(2014, level=1, axis=0, drop_level=False)
CO2bySourceG20_2014.head()
Sankeydf = FossilFuelConsumptionG20.drop(columns = ['Code'])
Sankeydf.index = [Sankeydf.Country, Sankeydf.Year]
Sankeydf['Total'] = Sankeydf['Oil (terawatt-hours)'] + Sankeydf['Gas (terawatt-hours)'] + Sankeydf['Coal (terawatt-hours)']
Sankeydf['Oil (terawatt-hours)'] = Sankeydf['Oil (terawatt-hours)']/Sankeydf['Total']*100
Sankeydf['Gas (terawatt-hours)'] = Sankeydf['Gas (terawatt-hours)']/Sankeydf['Total']*100
Sankeydf['Coal (terawatt-hours)'] = Sankeydf['Coal (terawatt-hours)']/Sankeydf['Total']*100
Sankeydf.drop(columns = ['Total','Country', 'Year'], inplace=True)
Sankeydf.head()
Sankeydf_1992 = Sankeydf.xs(1992, level=1, axis=0, drop_level=False)
Sankeydf_2002 = Sankeydf.xs(2002, level=1, axis=0, drop_level=False)
Sankeydf_2014 = Sankeydf.xs(2014, level=1, axis=0, drop_level=False)
Sankeydf_2014.head()
Sankeydf_2002.head()
display(Sankeydf_2002.stack().values)
display(CO2bySourceG20_2002.stack().values)
SankeyValues1992 = np.concatenate((Sankeydf_1992.stack().values, CO2bySourceG20_1992.stack().values))
SankeyValues2002 = np.concatenate((Sankeydf_2002.stack().values, CO2bySourceG20_2002.stack().values))
SankeyValues2014 = np.concatenate((Sankeydf_2014.stack().values, CO2bySourceG20_2014.stack().values))
SankeyValues2002
data = dict(type='sankey', valueformat = ".2f", valuesuffix = "%", node = dict(pad = 15,\
thickness = 20, line = dict(color = "black", width = 0.5),
#label the nodes of the Sankey diagram
label = ['Argentina', 'Australia', 'Brazil', 'Canada', 'China', 'France', 'Germany', 'India', 'Indonesia', 'Italy',\
'Japan', 'Mexico', 'Russia', 'Saudi Arabia', 'South Africa', 'South Korea', 'Turkey', 'United Kingdom', \
'United States', "Oil", "Gas", "Coal", 'Argentina CO2 Emissions', 'Australia CO2 Emissions', \
'Brazil CO2 Emissions', 'Canada CO2 Emissions', 'China CO2 Emissions', 'France CO2 Emissions', \
'Germany CO2 Emissions', 'India CO2 Emissions', 'Indonesia CO2 Emissions', 'Italy CO2 Emissions', \
'Japan CO2 Emissions', 'Mexico CO2 Emissions', 'Russia CO2 Emissions', 'Saudi Arabia CO2 Emissions', \
'South Africa CO2 Emissions', 'South Korea CO2 Emissions', 'Turkey CO2 Emissions', \
'United Kingdom CO2 Emissions', 'United States CO2 Emissions'],
#assign colors to the nodes
color = ['darkgreen', 'deepskyblue', 'aqua', 'darksalmon', 'darkmagenta', 'darkorchid', 'darkolivegreen', 'orangered', 'blue',\
'brown', 'burlywood', 'cadetblue','chartreuse', 'chocolate', 'coral', 'cornflowerblue','cornsilk', \
'crimson', 'darkkhaki','green','tomato', 'yellow','darkgreen', 'deepskyblue', 'aqua', 'darksalmon', 'darkmagenta',\
'darkorchid', 'darkolivegreen', 'orangered', 'blue','brown', 'burlywood', 'cadetblue','chartreuse', 'chocolate', \
'coral', 'cornflowerblue','cornsilk','crimson', 'darkkhaki']),
#sets the target(Fossil Fuels) to the sources(G20 Countries) and give tragets their value(percentage share)
link = dict(
source = [0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,13,14,14,14,15,\
15,15,16,16,16,17,17,17,18,18,18,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,\
20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21],
target = [19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,\
19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,22,22,22,23,23,23,24,24,24,25,25,25,26,26,26,\
27,27,27,28,28,28,29,29,29,30,30,30,31,31,31,32,32,32,33,33,33,34,34,34,35,35,35,36,36,36,37,37,37,38,38,38,\
39,39,39,40,40,40],
value = SankeyValues1992))
#sets the layout for the plot
layout = go.Layout(title = "Fossil Fuels Consumption and CO2 Emissions by G20 Countries (1992)", font = dict(size = 15))
fig = go.Figure(data=[data], layout=layout)
py.iplot(fig, validate=False) #plots the diagram
data = dict(type='sankey', valueformat = ".2f", valuesuffix = "%", node = dict(pad = 15,\
thickness = 20, line = dict(color = "black", width = 0.5),
#label the nodes of the Sankey diagram
label = ['Argentina', 'Australia', 'Brazil', 'Canada', 'China', 'France', 'Germany', 'India', 'Indonesia', 'Italy',\
'Japan', 'Mexico', 'Russia', 'Saudi Arabia', 'South Africa', 'South Korea', 'Turkey', 'United Kingdom', \
'United States', "Oil", "Gas", "Coal", 'Argentina CO2 Emissions', 'Australia CO2 Emissions', \
'Brazil CO2 Emissions', 'Canada CO2 Emissions', 'China CO2 Emissions', 'France CO2 Emissions', \
'Germany CO2 Emissions', 'India CO2 Emissions', 'Indonesia CO2 Emissions', 'Italy CO2 Emissions', \
'Japan CO2 Emissions', 'Mexico CO2 Emissions', 'Russia CO2 Emissions', 'Saudi Arabia CO2 Emissions', \
'South Africa CO2 Emissions', 'South Korea CO2 Emissions', 'Turkey CO2 Emissions', \
'United Kingdom CO2 Emissions', 'United States CO2 Emissions'],
#assign colors to the nodes
color = ['darkgreen', 'deepskyblue', 'aqua', 'darksalmon', 'darkmagenta', 'darkorchid', 'darkolivegreen', 'orangered', 'blue',\
'brown', 'burlywood', 'cadetblue','chartreuse', 'chocolate', 'coral', 'cornflowerblue','cornsilk', \
'crimson', 'darkkhaki','green','tomato', 'yellow','darkgreen', 'deepskyblue', 'aqua', 'darksalmon', 'darkmagenta',\
'darkorchid', 'darkolivegreen', 'orangered', 'blue','brown', 'burlywood', 'cadetblue','chartreuse', 'chocolate', \
'coral', 'cornflowerblue','cornsilk','crimson', 'darkkhaki']),
#sets the target(Fossil Fuels) to the sources(G20 Countries) and give tragets their value(percentage share)
link = dict(
source = [0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,13,14,14,14,15,\
15,15,16,16,16,17,17,17,18,18,18,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,\
20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21],
target = [19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,\
19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,22,22,22,23,23,23,24,24,24,25,25,25,26,26,26,\
27,27,27,28,28,28,29,29,29,30,30,30,31,31,31,32,32,32,33,33,33,34,34,34,35,35,35,36,36,36,37,37,37,38,38,38,\
39,39,39,40,40,40],
value = SankeyValues2002))
#sets the layout for the plot
layout = go.Layout(title = "Fossil Fuels Consumption and CO2 Emissions by G20 Countries (2002)", font = dict(size = 15))
fig = go.Figure(data=[data], layout=layout)
py.iplot(fig, validate=False) #plots the diagram
data = dict(type='sankey', valueformat = ".2f", valuesuffix = "%", node = dict(pad = 15,\
thickness = 20, line = dict(color = "black", width = 0.5),
#label the nodes of the Sankey diagram
label = ['Argentina', 'Australia', 'Brazil', 'Canada', 'China', 'France', 'Germany', 'India', 'Indonesia', 'Italy',\
'Japan', 'Mexico', 'Russia', 'Saudi Arabia', 'South Africa', 'South Korea', 'Turkey', 'United Kingdom', \
'United States', "Oil", "Gas", "Coal", 'Argentina CO2 Emissions', 'Australia CO2 Emissions', \
'Brazil CO2 Emissions', 'Canada CO2 Emissions', 'China CO2 Emissions', 'France CO2 Emissions', \
'Germany CO2 Emissions', 'India CO2 Emissions', 'Indonesia CO2 Emissions', 'Italy CO2 Emissions', \
'Japan CO2 Emissions', 'Mexico CO2 Emissions', 'Russia CO2 Emissions', 'Saudi Arabia CO2 Emissions', \
'South Africa CO2 Emissions', 'South Korea CO2 Emissions', 'Turkey CO2 Emissions', \
'United Kingdom CO2 Emissions', 'United States CO2 Emissions'],
#assign colors to the nodes
color = ['darkgreen', 'deepskyblue', 'aqua', 'darksalmon', 'darkmagenta', 'darkorchid', 'darkolivegreen', 'orangered', 'blue',\
'brown', 'burlywood', 'cadetblue','chartreuse', 'chocolate', 'coral', 'cornflowerblue','cornsilk', \
'crimson', 'darkkhaki','green','tomato', 'yellow','darkgreen', 'deepskyblue', 'aqua', 'darksalmon', 'darkmagenta',\
'darkorchid', 'darkolivegreen', 'orangered', 'blue','brown', 'burlywood', 'cadetblue','chartreuse', 'chocolate', \
'coral', 'cornflowerblue','cornsilk','crimson', 'darkkhaki']),
#sets the target(Fossil Fuels) to the sources(G20 Countries) and give tragets their value(percentage share)
link = dict(
source = [0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,11,11,11,12,12,12,13,13,13,14,14,14,15,\
15,15,16,16,16,17,17,17,18,18,18,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,\
20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21],
target = [19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,\
19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,19,20,21,22,22,22,23,23,23,24,24,24,25,25,25,26,26,26,\
27,27,27,28,28,28,29,29,29,30,30,30,31,31,31,32,32,32,33,33,33,34,34,34,35,35,35,36,36,36,37,37,37,38,38,38,\
39,39,39,40,40,40],
value = SankeyValues2014))
#sets the layout for the plot
layout = go.Layout(title = "Fossil Fuels Consumption and CO2 Emissions by G20 Countries (2014)", font = dict(size = 15))
fig = go.Figure(data=[data], layout=layout)
py.iplot(fig, validate=False) #plots the diagram
Sankey diagram allows to analyze the flow. Here we are using it analyze the impact of different fossil fuel consumption on the amount of air pollutant (CO2) emissions by the G20 countries in 1992, 2002 and 2014. We want to compare the changes every decade and picked these particular years due to limitation of data availability. In the Sankey diagram left side list of G20 countries represent the total of Oil, gas and Coal fossil fuel consumption represented by 100%, this is split between the Gas, Oil, and Coal based on these fossil fuel consumption by that country in that year. Similarly on the right side shows the 100% of each country's CO2 emissions and they map to the center Oil, Gas and Coal based on the source of these CO2 emissions. Of these fossil fuels Coal produces most CO2 emissions and considered bad for environment.[6] By comparing the these sankey diagrams US mix fossil fuel consumption was 27.94%, 44.47%, and 27.59%, respectively for Gas, Oil, and Coal in 1992. Which changed to 29.25%, 43.02%, and 27.73% in 2002 and 34.82%, 42.29%, and 22.89% in 2014. It is evident that US is trying to limit the consumption of Coal and move towards more cleaner fuel by reducing Coal consumption and increasing Gas consumption. Similar trend can be found in other countries .Also, when it comes to CO2 emissions percentages for US are 22.01%, 41.24%, and 36.75% in 1992, where as 21.92%, 41.22%, and 36.85% in 2002 and 27.56%, 40.68%, and 31.75% in 2014. From this it is evident that as Coal consumption decreased so does the CO2 emissions from Coal. In absolute figures US CO2 emissions in Million Tonnes in the years 1992, 2002, and 2014 are 4905.51908, 5636.695938, 5249.982734.
[6]Pounds of CO2 emitted per million British thermal units (Btu) of energy for various fuels
#defining a new dataframe, which is based on an old dataframe
G20_fossilfuel_CO2=FossilFuelConsumptionG20
#obtaining the total fossil by summing each column and defining a new column called total fossil fuels
G20_fossilfuel_CO2['Total Fossil Fuels']=FossilFuelConsumptionG20['Oil (terawatt-hours)']+FossilFuelConsumptionG20['Gas (terawatt-hours)']\
+FossilFuelConsumptionG20['Coal (terawatt-hours)']
G20_fossilfuel_CO2.head()
#dropped the columns that are not needed (inplace)
G20_fossilfuel_CO2.drop(['Oil (terawatt-hours)','Gas (terawatt-hours)','Coal (terawatt-hours)','Code'],axis=1,inplace=True)
G20_fossilfuel_CO2.head()
#creating a multiple dataframes from the previously defined dataframe(using boolean indexing)
G20_fossilfuel_CO2_1985=G20_fossilfuel_CO2[G20_fossilfuel_CO2.Year==1985]
G20_fossilfuel_CO2_2000=G20_fossilfuel_CO2[G20_fossilfuel_CO2.Year==2000]
G20_fossilfuel_CO2_2015=G20_fossilfuel_CO2[G20_fossilfuel_CO2.Year==2015]
G20_fossilfuel_CO2_1985.head()
CO2emissionsG20.head()
#creating new dataframes from previous dataframes (usiing boolean indexing) for C02 emissions
#also dropping the columns that are not needed
CO2emissionsG20_1985_1=CO2emissionsG20[CO2emissionsG20.Year==1985]
#CO2emissionsG20_1985_1.drop(['Code','Year'],axis=1,inplace=True)
CO2emissionsG20_1985_1=CO2emissionsG20_1985_1.drop(['Code','Year'],axis=1)
CO2emissionsG20_2000_1=CO2emissionsG20[CO2emissionsG20.Year==2000]
CO2emissionsG20_2000_1=CO2emissionsG20_2000_1.drop(['Code','Year'],axis=1)
CO2emissionsG20_2015_1=CO2emissionsG20[CO2emissionsG20.Year==2015]
CO2emissionsG20_2015_1=CO2emissionsG20_2015_1.drop(['Code','Year'],axis=1)
display(CO2emissionsG20_2000_1)
#merged different dataframes on the column named Country, with the outer method(which uses the union of keys from both dataframes)
G20_fossilfuel_CO2_1985_1=pd.merge(G20_fossilfuel_CO2_1985,CO2emissionsG20_1985_1, on='Country', how='outer')
G20_fossilfuel_CO2_2000_1=pd.merge(G20_fossilfuel_CO2_2000,CO2emissionsG20_2000_1, on='Country', how='outer')
G20_fossilfuel_CO2_2015_1=pd.merge(G20_fossilfuel_CO2_2015,CO2emissionsG20_2015_1, on='Country', how='outer')
G20_fossilfuel_CO2_1985_1.head()
#Creating a new dtaframe from previous years. The dataframe itself only has values of GDP per capita, which only has year
#equal to 1985,2000 and 2015
GDPpercapitaG20_1985=GDPpercapitaG20[GDPpercapitaG20.Year==1985]
GDPpercapitaG20_2000=GDPpercapitaG20[GDPpercapitaG20.Year==2000]
GDPpercapitaG20_2015=GDPpercapitaG20[GDPpercapitaG20.Year==2015]
#dropping the not needed columns
GDPpercapitaG20_1985.drop(['Code','Year'],axis=1,inplace=True)
GDPpercapitaG20_2000.drop(['Code','Year'],axis=1,inplace=True)
GDPpercapitaG20_2015.drop(['Code','Year'],axis=1,inplace=True)
#Merging the previously defined G20_fossilfuel_CO2_1985_1 dataframe with the GPD dataframe (only for year 1985,2000,2015)
G20_fossilfuel_CO2_1985_1=pd.merge(G20_fossilfuel_CO2_1985_1,GDPpercapitaG20_1985, on='Country', how='outer')
G20_fossilfuel_CO2_2000_1=pd.merge(G20_fossilfuel_CO2_2000_1,GDPpercapitaG20_2000, on='Country', how='outer')
G20_fossilfuel_CO2_2015_1=pd.merge(G20_fossilfuel_CO2_2015_1,GDPpercapitaG20_2015, on='Country', how='outer')
G20_fossilfuel_CO2_1985_1.head()
#graph that has a linear relationship between total fossil fuels used and annual CO2 emmisions
#the more total fossil fuels consumed the more annual co2 emissions produced by country. Also, the
#size of this grpah represents the GDP per capita per country
fig = px.scatter(G20_fossilfuel_CO2_1985_1, x="Total Fossil Fuels", y="Annual CO₂ emissions (Million tonnes)", color="Country",
size='GDP per capita (2011USD)', hover_data=['GDP per capita (2011USD)'],
title='GDP growth,and its respective impact on fossil fuel consumption and air pollutant emissions.(Year=1985)')
fig.show()
#For year 2000
fig = px.scatter(G20_fossilfuel_CO2_2000_1, x="Total Fossil Fuels", y="Annual CO₂ emissions (Million tonnes)", color="Country",
size='GDP per capita (2011USD)', hover_data=['GDP per capita (2011USD)'],
title='GDP growth,and its respective impact on fossil fuel consumption and air pollutant emissions.(Year=2000)')
fig.show()
#For year 2015
fig = px.scatter(G20_fossilfuel_CO2_2015_1, x="Total Fossil Fuels", y="Annual CO₂ emissions (Million tonnes)", color="Country",
size='GDP per capita (2011USD)', hover_data=['GDP per capita (2011USD)'],
title='GDP growth,and its respective impact on fossil fuel consumption and air pollutant emissions.(Year=2015)')
fig.show()
Scatter plot shows correlation betweeen the GDP growth of the G20 countries from 1985 to 2015 with their fossil fuel consumption and air pollutant emissions. In the plot Fossil fuel consumption is shown on x-axis and CO2 emissions on y-axis with GDP is represented by the size of the bubble.
#dropping unwanted columns
RenewableEnergyConsumtionG20_Hydro=RenewableEnergyConsumtionG20.drop(['Code','Wind (terawatt-hours)','Solar (terawatt-hours)','Other renewables (modern biofuels; geothermal; wave & tidal) (terawatt-hours)'],axis=1)
RenewableEnergyConsumtionG20_Wind=RenewableEnergyConsumtionG20.drop(['Code','Hydropower (terawatt-hours)','Solar (terawatt-hours)','Other renewables (modern biofuels; geothermal; wave & tidal) (terawatt-hours)'],axis=1)
RenewableEnergyConsumtionG20_Solar=RenewableEnergyConsumtionG20.drop(['Code','Hydropower (terawatt-hours)','Wind (terawatt-hours)','Other renewables (modern biofuels; geothermal; wave & tidal) (terawatt-hours)'],axis=1)
RenewableEnergyConsumtionG20_Other=RenewableEnergyConsumtionG20.drop(['Code','Hydropower (terawatt-hours)','Wind (terawatt-hours)','Solar (terawatt-hours)'],axis=1)
#visualizing dataframe
RenewableEnergyConsumtionG20_Wind.head()
#setting the index to column and also year(i.e multi index , hirarchical)
RenewableEnergyConsumtionG20_Wind.set_index(['Country','Year'], inplace = True)
RenewableEnergyConsumtionG20_Hydro.set_index(['Country','Year'], inplace = True)
RenewableEnergyConsumtionG20_Solar.set_index(['Country','Year'], inplace = True)
RenewableEnergyConsumtionG20_Other.set_index(['Country','Year'], inplace = True)
#obtaining the total green gass emissions from the same dataframe(by the vectorized summation method)
GreenGasEmissionsG20_1['Total Greehouse Gasses(Million tonnes)']=GreenGasEmissionsG20_1['SF₆ gases (Million tonnes)']+GreenGasEmissionsG20_1['PFC gases (Million tonnes)']\
+GreenGasEmissionsG20_1['HFC gases (Million tonnes)']+GreenGasEmissionsG20_1['Nitrous oxide (N₂O) (Million tonnes)']+GreenGasEmissionsG20_1['Methane (CH₄) (Million tonnes)']\
+GreenGasEmissionsG20_1['Carbon Dioxide (CO₂) (Million tonnes)']
GreenGasEmissionsG20_1.drop(columns = ['Country', 'Year'], inplace = True)
#dropping unwanted columns
GreenGasEmissionsG20_21=GreenGasEmissionsG20_1.drop(['SF₆ gases (Million tonnes)','PFC gases (Million tonnes)','HFC gases (Million tonnes)',\
'Nitrous oxide (N₂O) (Million tonnes)','Methane (CH₄) (Million tonnes)',\
'Carbon Dioxide (CO₂) (Million tonnes)'],axis=1)
GreenGasEmissionsG20_21.head()
#Mergeing dataframe on two indexes which are countries and year, using the inner method.
#This method use intersection of keys from both frames
GreenGasEmissionsG20_21merged1=pd.merge(GreenGasEmissionsG20_21,RenewableEnergyConsumtionG20_Wind, on=['Country','Year'],how='inner')
#merging dataframes by the previously defined method.
#This is done to obtain the final dataframe(which will be used to create visualziation)
GreenGasEmissionsG20_2_hydro_1=pd.merge(GreenGasEmissionsG20_21merged1,RenewableEnergyConsumtionG20_Hydro, on=['Country','Year'],how='inner')
GreenGasEmissionsG20_2_solar_1=pd.merge(GreenGasEmissionsG20_2_hydro_1,RenewableEnergyConsumtionG20_Solar, on=['Country','Year'],how='inner')
RenewableEnergyConsumtionG20_Total=pd.merge(GreenGasEmissionsG20_2_solar_1,RenewableEnergyConsumtionG20_Other, on=['Country','Year'],how='inner')
#creating a new dataframe that stacks by country an reset its idex of country
RenewableEnergyConsumtionG20_Total_1=RenewableEnergyConsumtionG20_Total.stack().reset_index()
#renaming the columns of previously defined columns to use them in the figure.
RenewableEnergyConsumtionG20_Total_1.rename(columns={"level_2": "Parameter"}, inplace = True)
RenewableEnergyConsumtionG20_Total_1.rename(columns={0: "Values"}, inplace = True)
RenewableEnergyConsumtionG20_Total_1.head()
#Plotting figure without log axis
fig = px.line(RenewableEnergyConsumtionG20_Total_1, x='Year', y='Values',color='Parameter',
line_group='Country', hover_name='Country')
fig.update_layout(legend_orientation="h")
fig.show()
#Plotting figure wih log axis
fig = px.line(RenewableEnergyConsumtionG20_Total_1, x='Year', y='Values',color='Parameter',
line_group='Country', hover_name='Country')
fig.update_layout(xaxis_type="log", yaxis_type="log", legend_orientation="h")
fig.show()
The line graph shows the trend of renewable energy consumption of the G20 countries from 1985 to 2014 with their greenhouse gas emissions. In the plot year is shown on x-axis and greenhouse gas emissions and renewable energy consumption on y-axis. Our obervations are given below:
Overall, as countries grow economically (GDP), their energy demand expands and as a result consumption of fossil fuels increases. Consequently, more green house gases including CO2 are released. These green house gases are harmful to the humans, animals and the environment. Using more renewable energy sources decreses the dependency on fossil fuels to meet the ever increasing energy demand and decreases the green house gas emissions. Hence, all coutries should try to increase their renewable energy source percentage in their energy portfolio.
Include more variables (Datasets) such as population,forest area, and vegetation to analyze and emphasize the effect of using more renewable sources of energy in reducing the green house gases.